Ext.define('EUniversitySuperAdmin.controller.actiontree', {
 
    extend: 'Ext.app.Controller',
  
    views: [
     		'actiontree.rightmenu'
        	
    		],
      refs : [{
        ref: 'rightmenu',
        selector: 'rightmenu'
       
    },{
    	ref :'viewport',
    	selector : 'viewport'
    }],
    LoadDataInForm:function(view, record, item, index, e){
    	
    	var dataextract=record.get('id').split("_");
    	
    	//alert(dataextract[0]);
    	if(dataextract[0]=="PL"){
    		Ext.getCmp("tabs").add(
    				{
    					title: dataextract[1],/////////////////////////
    					height:'300',
    					closable:true,
    			        xtype : "component",
    			        id    : "management_"+Ext.getCmp("tabs").items.length+1,
    			        loadScripts: true,
    			        scripts: true,
    			        loader: {
    			        	autoLoad: true,
    			             loadMask: true,
    			        	 url: 'http://localhost/moodle2.1/login/index.php',
    			        	
    			        	 scripts: true,
    			        	 method:'post',
    			        	 mode: 'frame',
    			        	 nocache: true,
       			        	 params:{username:'admin',password:'@admin123A'}
    			        	}
    			      /*  autoEl : {
    			            tag : "iframe",
    			            src : record.get('text'),
    			            method:'post',
    			            params:{username:'admin',password:'@admin123A'}
    			        }*/
    				    
    				}
    		).show();
    		
    	}else if(dataextract[0]=="LOT"){
    		//=================================================================
        	var me= this;
        	//chargement des columns de gride
        	
        	
        	
        	Ext.Ajax.request({
        		url: 'pilotage/projectbord/dycolumnboard',
        		 params: { id:dataextract[3],idplan:dataextract[2] },
    		    success: function(response1){
    		    	globalColumn=response1.responseText;
    		    	//chargement des data de store
    		    	 Ext.Ajax.request({
    		    		 url: 'pilotage/projectbord/loaddataboard',
    		    		 params: { id:dataextract[1] ,idplan:dataextract[2] },
    		 		    success: function(response){
    		 		    	globalStore=response.responseText;
    		 		    	//chargement des donnÃ©e de fields de store
    		 		    	Ext.Ajax.request({
    		 		    		url: 'pilotage/projectbord/jsonstructerdataboard',
    		 		    		params: { id:dataextract[3] ,idplan:dataextract[2] },
    		 				    success: function(responseh){
    		 				    	
    		 				    	Ext.Ajax.request({
    	    		 		    		url: 'pilotage/projectbord/piedashbord',
    	    		 		    		params: { id:dataextract[3] ,idplan:dataextract[2],idproject:dataextract[1] },
    	    		 				    success: function(responsechart){
    		 				    	
		    		 				    	
		    		 				    	storetest = Ext.create('Ext.data.JsonStore', {
		    		 				    		fields:Ext.JSON.decode(responseh.responseText),
		     					       			data:Ext.JSON.decode(response.responseText)
		    		 				        });
		    		 				    	
		    		 				    	
		    		 				    	storechart=Ext.create('Ext.data.JsonStore', {
		    		 				    		fields:Ext.JSON.decode(responseh.responseText),
			 					       			data:Ext.JSON.decode(response.responseText)
		    		 				    	});
		    		 				    	var listitems=[
		    		 				    	               	{
					    		 				    		xtype: 'analyticboardgridboard',
					    		 				    		width:"50%",
		    				 					        	autoHeight:true,
							 					        	store :storechart,
							 					        	columns :{
							 					        	           items:Ext.JSON.decode(response1.responseText),
									 					        	    defaults: { 
									 				                    sortable: true, 
									 				                   forceFit:true,
									 				                    width: 100 
							 					        	           } 
							 					        	         },
							 					        	split:true,
							 					        	
							 					        	region:'center'
							 					        	
					    		 				    		
					    		 				    	}];
		    		 				    	if(responsechart.responseText!="NONE"){
		    		 				    		listitems.push(
		    		 				    		{
		    		 				    			xtype: 'chartboard',
		    		 				    			width:"50%",
		    		 				    			split:true,
		    		 				    			collapsible: true,
		    		 				               collapsed: true,
    				 					        	autoHeight:true,
    				 					        	id: 'chartCmp',
    				 					        	store:storechart,
    				 					        	form:false,
    				 					        	series: [Ext.JSON.decode(responsechart.responseText)],
    				 					        	region:'east'
		    		 				    		}		
		    		 				    		);
		    		 				    	}
		    		 				    	
		    				 		    	 Ext.getCmp('tabs').add({
		    				 					        title: 'Analitic Board',
		    				 					        height:'300',
		    				 					        tbar: [{
		    				 					            text: 'Enregistrer la chart',
		    				 					            handler: function() {
		    				 					                Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
		    				 					                    if(choice == 'yes'){
		    				 					                        Ext.getCmp('chartCmp').save({
		    				 					                            type: 'image/png'
		    				 					                        });
		    				 					                    }
		    				 					                });
		    				 					            }
		    				 					        }],
		    				 					       layout: {
		    				 					    	    type: 'border', 
		    				 					    	    split:true,
		    				 					    	   padding: 5
		    				 					    	 },
		    				 					        items:listitems,

		    				 					        closable:true
		    				 					    }).show();
    	    		 				    }
    		 				    	});
		
		    		 				    }
    		 		    	});
    		 		    	
    		 		    },
    		 	        failure: function(response, opts) {}
    		           
    		 		});
    		    },
    	        failure: function(response, opts) {
              }
              
    		});
    		
    		
    		//========================================================================
    	}
    	
    	
    	
    	
    	
    },
    init: function() {
    	
    	 this.control({
             
             'rightmenu' :{
            	 itemclick:this.LoadDataInForm
             }
         });
    	
    	 var store = Ext.create('Ext.data.TreeStore', {
    		 model : 'EUniversitySuperAdmin.model.actiontree',
    			proxy: {
    				type: 'ajax',
    				 actionMethods: {
    			           read: 'POST'
    			       },
    				url: 'pilotage/projectbord/projectdatas'
    			},
    			root:{
	   		         text: 'Analyse',
	   		         expanded: false
	   		       
	   		     },
    			folderSort: true,
    			sorters: [{
    				property: 'text',
    				direction: 'ASC'
    			}]
    		});
    	 
    	 
    	 var view = Ext.widget("rightmenu",{
    		 	store: store, 
    			height: 300,
    			width: 250
    			
	    	});
	    	
	    	this.getViewport().layout.regions.west.add(view);
    	      
    } ,
    onPanelRendered:function(){
    	 
    }
    
});